package com.bustle.product.dto.product;

import java.util.List;
import java.util.Vector;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.bustle.commons.CollectionManager;
import com.bustle.commons.MapConverter;
import com.bustle.commons.data.dao.Dao;
import com.bustle.commons.data.dto.DtoDao;
import com.bustle.product.data.Product;
import com.bustle.product.data.Product.ProductType;
import com.bustle.product.data.dao.ProductDao;

public interface ProductDtoDao extends Dao<Integer, ProductDto>
{
  public List<ProductDto> retrieveProductsDtoByTypeAndProvider(ProductType productType, Integer idProvider);
  public List<ProductDto> retrieveProductsDtoByProductType(ProductType productType);
  public List<ProductDto> retrieveProductsDtoByIdProvider(int idProvider);

  @Stateless
  public class DefaultProductDtoDao extends DtoDao<Integer, ProductDto, Product> implements ProductDtoDao
  {

    @Override
    protected Dao<Integer, Product> getDao()
    {
      return productDao;
    }

    @Override
    protected MapConverter<ProductDto, Product> getDtoToDataMapConverter()
    {
      return dtoToProductConverter;
    }

    @Override
    protected MapConverter<Product, ProductDto> getDataToDtoMapConverter()
    {
      return productToDtoConverter;
    }

    @Override
    public List<ProductDto> retrieveProductsDtoByTypeAndProvider(ProductType paramProductType, Integer paramIdProvider)
    {
      List<ProductDto> productDtos = new Vector<>();
      collectionManager.addAll(productDao.retrieveProductsByTypeAndProvider(paramProductType, paramIdProvider), productDtos, getDataToDtoMapConverter());
      return productDtos;
    }

    @Override
    public List<ProductDto> retrieveProductsDtoByProductType(ProductType paramProductType)
    {
      List<ProductDto> productDtos = new Vector<>();
      collectionManager.addAll(productDao.retrieveProductsByProductType(paramProductType), productDtos, getDataToDtoMapConverter());
      return productDtos;
    }

    @Override
    public List<ProductDto> retrieveProductsDtoByIdProvider(int paramIdProvider)
    {
      List<ProductDto> productDtos = new Vector<>();
      collectionManager.addAll(productDao.retrieveProductsByIdProvider(paramIdProvider), productDtos, getDataToDtoMapConverter());
      return productDtos;
    }

    @EJB
    protected ProductDao productDao;
    @EJB
    protected CollectionManager collectionManager;
    @EJB
    protected DtoToProductMapConverter dtoToProductConverter;
    @EJB
    protected ProductToDtoMapConverter productToDtoConverter;
  }

}
